<?php
/*
银行表查询方法
selectBank($where,$order)
addBank($data)
*/

namespace Home\Model;
use Think\Model;
class BankModel extends Model{

//查询bank
  public function selectBank($where,$p,$n){
    $banks = $this->where($where)->page($p.','.$n)->order('bank_id desc')->select();
    if($banks){
      return $banks;
    }
    else{
      return false;
    }
  }

//添加bank
  public function addBank($data){
    $res = $this->add($data);
    if($res){
      return $res;
    }
    else{
      return false;
    }
  }

  //根据id查询
  public function findData($id){
    $res = $this->where(array('bank_id'=>$id))->find();
    return $res;
  }
  
  public function selectChildBank($id){
      $res = $this->where(array('pid'=>$id))->select();
    return $res;
  }

//根据条件查询是否有相同的
  public function findSameBank($val,$pid,$id){
    if(!$id && $pid){
      $bank = $this->where(array('bank_name'=>$val, 'pid'=>$pid,'isdel'=>'0'))->find();
    }
    if($val && $pid && $id){
      $bank = $this->where(array('bank_name'=>$val , 'bank_id'=>array('neq',$id) , 'pid'=>$pid,'isdel'=>'0'))->find();
    }
    if($bank){
      return $bank;
    }
    else{
      return false;
    }

  }

//保存修改
  public function saveBank($id,$data){
    $bank = $this->where(array('bank_id'=>$id))->save($data);
    if($bank){
      return ture;
    }
    else{
      return false;
    }
  }

  //查询数据条数
  public function countBank($where){
    $num  = $this->where($where)->count();
    return $num;
  }














}
